
package com.hulk.ratel.persistence;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.generator.AutoGenerator;

import java.util.Scanner;

/**
 * <p>
 * Mysql代码生成器
 * </p>
 * t_dict_type,t_dict_code,t_txncode,t_txncode_org_clazz,t_partner_org_route,t_errcode_convert,t_partner_info,t_partner_key,t_merchant_info,t_org_info,t_log_txn_pay_record,t_notify_record
 * 多张表中间用逗号分隔, 注意中间不能有空格。
 * @author hulk
 */
public class MysqlGenerator extends SuperGenerator {


    public static void main(String[] args){
        MysqlGenerator   ms= new MysqlGenerator();
        ms.generator(scanner("表名"));
    }

    /**
     * <p>
     * MySQL generator
     * </p>
     */
    public void generator(String tableName) {

        // 代码生成器
        AutoGenerator mpg = getAutoGenerator(tableName);
        mpg.execute();
        if (tableName == null) {
            System.err.println(" Generator Success !");
        } else {
            System.err.println(" TableName【 " + tableName + " 】" + "Generator Success !");

        }
    }



    /**
     * <p>
     * 读取控制台内容
     * </p>
     */
    private static String scanner(String tip) {
        Scanner scanner = new Scanner(System.in);
        StringBuilder help = new StringBuilder();
        help.append("请输入" + tip + "：");
        System.out.println(help.toString());
        if (scanner.hasNext()) {
            String ipt = scanner.next();
            if (StrUtil.isNotBlank(ipt)) {
                return ipt;
            }
        }
        throw new RuntimeException("请输入正确的" + tip + "！");
    }

}
